package com.alphawavesgames.engine.utilities;

/**
 * A Camera class structure that can be manipulated to focus on given points or
 * moved around when commanded.
 *
 * @author Andrew Dyer
 */
public class Camera {

    /** The leftmost side of the camera. */
    private double mX;
    /** The topmost point of the camera. */
    private double mY;
    /** The camera's width. */
    private int mWidth;
    /** The camera's height. */
    private int mHeight;

    /**
     * Creates a camera based on the given top-left point (x, y) and the given
     * width and height.
     *
     * @param x The leftmost point of the camera.
     * @param y Top topmost point of the camera.
     * @param width How wide the camera spans.
     * @param height How high the camera spans.
     */
    public Camera(int x, int y, int width, int height) {
        mX = x;
        mY = y;

        mWidth = width;
        mHeight = height;
    }

    /**
     * Reports if the given point (x, y) is within the camera's view.
     *
     * @param x The x-coordinate to be tested.
     * @param y The y-coordinate to be tested.
     * @return True of the point is within the view of the camera. False if not.
     */
    public boolean contains(double x, double y) {
        return (x >= mX && x <= (mX + mWidth)
                && y >= mY && y <= (mY + mHeight));
    }

    /**
     * Moves the top-left corner of the camera to the given point (x, y).
     *
     * @param x The x-coordinate to move to.
     * @param y The y-coordinate to move to.
     */
    public void setPosition(double x, double y) {
        mX = x;
        mY = y;
    }

    /**
     * Moves the camera to centre on the given point (x, y).
     *
     * @param x The x-coordinate to look at.
     * @param y The y-coordinate to look at.
     */
    public void lookAt(double x, double y) {
        mX = x - (mWidth >> 1);
        mY = y - (mHeight >> 1);
    }

    /**
     * Gives the height dimension of the camera.
     *
     * @return The height of the camera.
     */
    public int getHeight() {
        return mHeight;
    }

    /**
     * Gives the width dimension of the camera.
     *
     * @return The height of the camera.
     */
    public int getWidth() {
        return mWidth;
    }

    /**
     * Gives the left-most point of the camera.
     *
     * @return The left-most point.
     */
    public double getX() {
        return mX;
    }

    /**
     * Gives the top-most point of the camera.
     *
     * @return The top-most point.
     */
    public double getY() {
        return mY;
    }

    /**
     * Changes the dimensions of the camera to those given.
     *
     * @param width The width to set the camera to.
     * @param height The Height to set the camera to.
     */
    public void setSize(int width, int height) {
        mWidth = width;
        mHeight = height;
    }

    /**
     * Moves the camera a set vector based on the given values.
     *
     * @param dX The distance change in the x-axis.
     * @param dY The distance change in the y-axis.
     */
    public void move(double dX, double dY) {
        mX += dX;
        mY += dY;
    }

    /**
     * Moves the camera's view (centre point) toward the given location (x, y).
     *
     * @param x
     * @param y
     * @param elapsedTime
     */
    public void panViewTo(int x, int y, long elapsedTime) {
        
    }
}
